<template>
  <div class="edit">
    <el-card class="box-card">
      <el-form ref="form" :model="form" :rules="rules" label-width="200px">
        <el-form-item label="账户设备码绑定数量限制" prop="deviceMax">
          <el-input-number v-model="form.deviceMax" placeholder="请输入账户设备码绑定数量限制" />
        </el-form-item>

        <el-form-item label="超出设备码限制的提示语" prop="outDesc">
          <el-input type="textarea" :rows="5" placeholder="请输入内容" v-model="form.outDesc"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="submitForm">确定</el-button>
          <el-button @click="cancel">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
  </div>
</template>
<script>
import { getDevice, saveDevice } from "@/api/system/appStart";

export default {
  name: "AppStart",
  data() {
    return {
      // 表单参数
      form: {
        deviceMax: 0,
        outDesc: ""
      },
      // 表单校验
      rules: {
        deviceMax: [{ required: true, message: "请输入账户设备码绑定数量限制" }]
      }
    };
  },
  mounted() {
    this.getEditInfo();
  },
  methods: {
    getEditInfo() {
      getDevice().then(response => {
        this.form = response.data
          ? response.data
          : { deviceMax: 0, outDesc: "" };
      });
    },

    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          saveDevice(this.form).then(response => {
            if (response.code === 200) {
              this.msgSuccess("修改成功");
            }
          });
        }
      });
    },
    // 重置按钮
    cancel() {
      this.getEditInfo();
      this.resetForm("form");
    }
  }
};
</script>
